﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using MySql.Data.MySqlClient;

namespace FMixPlayer
{
    public partial class FormLogin : Form
    {
        
        MySqlConnection myConnection;// = new MySqlConnection(Form1.Connect);
        MySqlCommand myCommand;// = new MySqlCommand(CommandText, myConnection);

        public FormLogin()
        {
            InitializeComponent();
        }

        private void buttonLogin_Click(object sender, EventArgs e)
        {
            Login();
        }

        private void Login()
        {
            string startCommand = "SELECT password FROM users WHERE login='" + textBoxLogin.Text + "'";

            myConnection = new MySqlConnection(FormMain.Connect);
            myCommand = new MySqlCommand(startCommand, myConnection);


            myConnection.Open();
            string pass = "|empty|";
            try
            {
                pass = myCommand.ExecuteScalar().ToString();
            }
            catch
            {
                labelWrongPass.Text = "Неверное имя пользователя или пароль!";
            }
            if (pass == textBoxPassword.Text)
            {
                FormMain MainForm = new FormMain(textBoxLogin.Text);
                MainForm.Show();
                this.Hide();
            }
            else
            {
                labelWrongPass.Text = "Неверное имя пользователя или пароль!";
            }
        }
        private void buttonExit_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void textBoxPassword_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == 13) Login();
        }
    }
}
